package com.LostAndFound.web.servlet;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.LostAndFound.service.SearchForRecordService;
import com.google.gson.Gson;

public class SearchForRecordServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;

	SearchForRecordService service = new SearchForRecordService();
	
	// 得到所有的已经成功的记录
	public void findAllSuccessRecordsForEasyUI(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String cid = request.getParameter("cid");
		String whatFlag = request.getParameter("whatFlag");
		if(cid==null) {
			cid="0";
		}
		if(whatFlag==null) {
			whatFlag = "0";
		}
		// 当前页
		int pageNumber = Integer.parseInt(request.getParameter("page"));
		// 每页总条数
		int pageSize = Integer.parseInt(request.getParameter("rows"));
		// 总记录数
		int total = service.getTotalRecordsForEasyUI(cid,whatFlag);
		// 记录详情
		List<Map<String,Object>> mapList = service.findAllSuccessRecordsForEasyUI(pageNumber,pageSize,cid,whatFlag);
		
		Gson gson = new Gson();
		String rows = gson.toJson(mapList);
		response.setContentType("text/html;charset=utf-8");
		response.getWriter().write("{\"total\":"+total+",\"rows\":"+rows+"}");	
		
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
}